home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / AMACC_-_Ma20312211152006.psc / Library / Class Modules / clsMyMenuXP.cls
Text File  |  2002-08-10  |  12KB  |  339 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsMyMenu"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. ' ======================================================================
  16. ' See the module modMenus:ReadMe for rules on using this class
  17. ' ======================================================================
  18.  
  19. Private ImageLister As Control
  20. ' name of menus imagelist, can't use handle 'cause it can change per MSDN
  21. Public MainMenuID As Long  ' handle to form's main menu
  22. Public OldWinProc As Long  ' handle to form's window message processor
  23. Public ChildStatus As Byte ' 1 indicates a child
  24. Public ParentForm As Long  ' for MDI children, this is the MDI parent -- for others it is it's own handle
  25. Private MyMI() As MenuDataInformation       ' collection of menuitems
  26. Private menuIDs As Collection               ' index to myMI array
  27. Private mIDcurrent As Long                  ' current menu item
  28. Private MyPanels() As PanelDataInformation
  29. Private PanelData As Collection
  30. Private pIDcurrent As Long
  31. Private MDIchildren As Collection
  32.  
  33. Property Get TotalIcons() As Long
  34.     On Error Resume Next
  35.     TotalIcons = ImageLister.ListImages.Count
  36. End Property
  37.  
  38. Property Let Icon(lValue As Long)
  39.     MyMI(menuIDs(mIDcurrent)).Icon = lValue
  40. End Property
  41. Property Get Icon() As Long
  42.     Icon = MyMI(menuIDs(mIDcurrent)).Icon
  43. End Property
  44.  
  45. Property Let ItemHeight(lValue As Long)
  46.     MyMI(menuIDs(mIDcurrent)).ItemHeight = lValue
  47. End Property
  48. Property Get ItemHeight() As Long
  49.     ItemHeight = MyMI(menuIDs(mIDcurrent)).ItemHeight
  50. End Property
  51. Property Let ItemWidth(lValue As Long)
  52.     MyMI(menuIDs(mIDcurrent)).ItemWidth = lValue
  53. End Property
  54. Property Get ItemWidth() As Long
  55.     ItemWidth = MyMI(menuIDs(mIDcurrent)).ItemWidth
  56. End Property
  57. Property Let HotKeyPos(lValue As Long)
  58.     MyMI(menuIDs(mIDcurrent)).HotKeyPos = lValue
  59. End Property
  60. Property Get HotKeyPos() As Long
  61.     HotKeyPos = MyMI(menuIDs(mIDcurrent)).HotKeyPos
  62. End Property
  63.  
  64. Property Let Status(lValue As Long)
  65.     MyMI(menuIDs(mIDcurrent)).Status = lValue
  66. End Property
  67. Property Get Status() As Long
  68.     Status = MyMI(menuIDs(mIDcurrent)).Status
  69. End Property
  70.  
  71. Property Let Caption(sValue As String)
  72.     MyMI(menuIDs(mIDcurrent)).Caption = sValue
  73. End Property
  74. Property Get Caption() As String
  75.     Caption = MyMI(menuIDs(mIDcurrent)).Caption
  76. End Property
  77.  
  78. Property Get ImageViewerObj() As Control
  79.     On Error Resume Next
  80.     Set ImageViewerObj = ImageLister
  81. End Property
  82. Property Get ImageViewer() As Long
  83.    On Error Resume Next
  84.    ImageViewer = ImageLister.hImageList
  85. End Property
  86. Public Sub SetImageViewer(vObject As Control)
  87.     Set ImageLister = vObject
  88. End Sub
  89.  
  90. Property Get OriginalCaption() As String
  91.     OriginalCaption = MyMI(menuIDs(mIDcurrent)).OriginalCaption
  92. End Property
  93. Property Let OriginalCaption(sValue As String)
  94.     MyMI(menuIDs(mIDcurrent)).OriginalCaption = sValue
  95. End Property
  96.  
  97. Property Get SideBarIsText() As Boolean
  98.     On Error Resume Next
  99.     SideBarIsText = (MyPanels(CStr(pIDcurrent)).Status And 4) = 4
  100. End Property
  101. Property Get SideBarItem() As Long
  102.     SideBarItem = MyPanels(CStr(pIDcurrent)).SBarIcon
  103. End Property
  104. Property Get SideBarWidth() As Long
  105.     SideBarWidth = MyPanels(CStr(pIDcurrent)).SideBar
  106. End Property
  107. Property Get PanelWidth() As Long
  108.     PanelWidth = MyPanels(CStr(pIDcurrent)).Width
  109. End Property
  110. Property Get PanelIDcount() As Long
  111.     On Error Resume Next
  112.     PanelIDcount = PanelData.Count
  113. End Property
  114. Property Get PanelHeight() As Long
  115.     On Error Resume Next
  116.     PanelHeight = MyPanels(CStr(pIDcurrent)).Height
  117. End Property
  118. Property Get HotKeyEdge() As Integer
  119.     HotKeyEdge = CInt(MyPanels(CStr(pIDcurrent)).HKeyPos)
  120. End Property
  121.  
  122. Public Function GetSetMDIchildSysMenu(lValue As Long, bSet As Boolean) As Boolean
  123. On Error Resume Next
  124. Dim lHwnd As Long
  125. If bSet = True Then
  126.     If MDIchildren Is Nothing Then Set MDIchildren = New Collection
  127.     lHwnd = MDIchildren(CStr(lValue))
  128.     If lHwnd = 0 Then MDIchildren.Add MDIchildren.Count + 1, CStr(lValue)
  129. Else
  130.     lHwnd = MDIchildren(CStr(lValue))
  131.     GetSetMDIchildSysMenu = (lHwnd <> 0)
  132. End If
  133. Err.Clear
  134. End Function
  135.  
  136. Property Get MenuIDcount() As Integer
  137. ' =====================================================================
  138. ' Simply returns the number of menu items processed
  139. ' =====================================================================
  140.     On Error Resume Next
  141.     MenuIDcount = menuIDs.Count
  142. End Property
  143.  
  144. Public Sub UpdatePanelID(vData() As Long, sText As String, bPartial As Boolean)
  145.     On Error Resume Next
  146.     With MyPanels(CStr(pIDcurrent))
  147.         .Width = vData(0)
  148.         .Height = vData(1)
  149.         .HKeyPos = vData(2)
  150.         .PanelIcon = vData(3)
  151.         If bPartial = False Then
  152.             'Debug.Print "full update on paneldata"
  153.             .SideBar = vData(4)
  154.             .SideBarXY = vData(5)
  155.             .BColor = vData(6)
  156.             .FColor = vData(7)
  157.             .Caption = sText
  158.             .Status = vData(9)
  159.             .SBarIcon = vData(10)
  160.         End If
  161.     End With
  162. End Sub
  163.  
  164. Public Sub GetPanelInformation(vData() As Long, sText As String)
  165. On Error Resume Next
  166. ReDim vData(0 To 10)
  167. With MyPanels(PanelData(CStr(MyMI(menuIDs(mIDcurrent)).Parent)))
  168.     vData(0) = .Width + 16
  169.     vData(1) = .Height
  170.     vData(2) = .HKeyPos
  171.     vData(3) = .PanelIcon
  172.     vData(4) = .SideBar
  173.     vData(5) = .SideBarXY
  174.     vData(6) = .BColor
  175.     vData(7) = .FColor
  176.     sText = .Caption
  177.     vData(9) = .Status
  178.     vData(10) = .SBarIcon
  179. End With
  180. End Sub
  181.  
  182. Public Function SetMenuID(iID As Long, hSubMenu As Long, byPosition As Boolean, Optional bAlwaysCreate As Boolean = True) As Boolean
  183. ' =====================================================================
  184. ' Used to create a new reference to a menu item or point to
  185. ' an existing reference
  186. ' =====================================================================
  187.  
  188.     On Error Resume Next
  189.     ' we reference passed menu item, if we don't have a reference
  190.     ' an error occurs which triggers a new reference if the
  191.     ' bAlwaysCreate boolean is set to true
  192.     If byPosition Then
  193.         ' menu item is positional (i.e., 1,2,3)
  194.         mIDcurrent = iID
  195.     Else
  196.         ' menu item is by ID vs position
  197.         mIDcurrent = menuIDs(CStr(iID) & "." & CStr(hSubMenu))
  198.     End If
  199.     If Err Then ' new reference
  200.         If bAlwaysCreate = True Then
  201.             ' let's add a new reference & use the menu ID as a key
  202.             menuIDs.Add menuIDs.Count + 1, CStr(iID) & "." & CStr(hSubMenu)
  203.             mIDcurrent = menuIDs.Count
  204.             ' now we will add an MyMI array
  205.             ReDim Preserve MyMI(1 To menuIDs.Count)
  206.             MyMI(menuIDs(mIDcurrent)).ID = iID
  207.             MyMI(menuIDs(mIDcurrent)).Parent = hSubMenu
  208.             ' return a value indicating this is a new add
  209.             SetMenuID = True
  210.             Err.Clear
  211.             pIDcurrent = PanelData(CStr(hSubMenu))
  212.             If Err Then
  213.                 Err.Clear
  214.                 PanelData.Add PanelData.Count + 1, CStr(hSubMenu)
  215.                 ReDim Preserve MyPanels(1 To PanelData.Count)
  216.                 MyPanels(PanelData.Count).ID = hSubMenu
  217.                 'Debug.Print "new panel created-count="; hSubMenu; PanelData.Count
  218.             End If
  219.         End If
  220.     Else    ' reference already exists
  221.         ' if the following flag wasn't set, then the drawing/measuring
  222.         ' routine wants to know if we have a reference
  223.         ' so we set return to true if so
  224.         ' otherwise, the menu metrics is calling this and we
  225.         ' need to return false indicating this is not a new add
  226.         If bAlwaysCreate = False Then SetMenuID = True
  227.     End If
  228.     pIDcurrent = PanelData(CStr(hSubMenu))
  229. End Function
  230.  
  231. Public Sub GetIconData(vData() As Long, IconIndex As Long)
  232. ' =====================================================================
  233. ' Returns image handle, type and icon index/transparency option
  234. ' when drawing routine requests it
  235. ' =====================================================================
  236.     On Error Resume Next
  237.     ReDim vData(0 To 2)
  238.     If Not ImageLister Is Nothing Then
  239.         vData(0) = ImageLister.ListImages(IconIndex).Picture.Handle
  240.         vData(1) = ImageLister.ListImages(IconIndex).Picture.Type
  241.         If (MyMI(menuIDs(mIDcurrent)).Status And 4) = 4 Then
  242.             vData(2) = 1
  243.         Else
  244.             If (MyMI(menuIDs(mIDcurrent)).Status And 8) = 8 Then vData(2) = 2
  245.         End If
  246.     End If
  247. End Sub
  248.  
  249. Public Function GetPanelID(iID As Long) As Long
  250. ' =====================================================================
  251. ' Returns then actual menuID and related submenu item for
  252. ' a stored menuitem -- used in preparation for the DeleteMenuItem sub
  253. ' =====================================================================
  254. On Error Resume Next
  255. GetPanelID = MyPanels(PanelData.Item(iID)).ID
  256. End Function
  257.  
  258. Public Sub PurgeObsoleteMenus(hSubMenu As Long)
  259. Dim newMyMI() As MenuDataInformation, newMyPanels() As PanelDataInformation
  260. Dim Looper As Long, lCounter As Long
  261. On Error GoTo ExitSub
  262. If menuIDs.Count Then
  263.     ReDim newMyMI(1 To menuIDs.Count)
  264.     lCounter = 1
  265.     For Looper = menuIDs.Count To 1 Step -1
  266.         If MyMI(menuIDs.Item(Looper)).Parent <> hSubMenu Then
  267.             newMyMI(lCounter) = MyMI(menuIDs.Item(Looper))
  268.             lCounter = lCounter + 1
  269.         End If
  270.     Next
  271.     If lCounter - 1 Then
  272.         Erase MyMI
  273.         ReDim MyMI(1 To lCounter - 1)
  274.         Set menuIDs = Nothing
  275.         Set menuIDs = New Collection
  276.         For Looper = 1 To lCounter - 1
  277.             MyMI(Looper) = newMyMI(Looper)
  278.             menuIDs.Add Looper, CStr(newMyMI(Looper).ID) & "." & CStr(newMyMI(Looper).Parent)
  279.         Next
  280.         'Debug.Print "Finished indexing menuitems"
  281.     End If
  282.     Erase newMyMI
  283. End If
  284. If PanelData.Count Then
  285.     ReDim newMyPanels(1 To PanelData.Count)
  286.     lCounter = 1
  287.     For Looper = PanelData.Count To 1 Step -1
  288.         pIDcurrent = Looper
  289.         If MyPanels(PanelData.Item(Looper)).ID <> hSubMenu Then
  290.             newMyPanels(lCounter) = MyPanels(PanelData.Item(Looper))
  291.             If SideBarIsText = True Then DeleteObject MyPanels(PanelData.Item(Looper)).SBarIcon
  292.             lCounter = lCounter + 1
  293.         End If
  294.     Next
  295.     If lCounter - 1 Then
  296.         Erase MyPanels
  297.         ReDim MyPanels(1 To lCounter - 1)
  298.         Set PanelData = Nothing
  299.         Set PanelData = New Collection
  300.         For Looper = 1 To lCounter - 1
  301.             MyPanels(Looper) = newMyPanels(Looper)
  302.             PanelData.Add Looper, CStr(newMyPanels(Looper).ID)
  303.         Next
  304.         'Debug.Print "Finished Indexing panels"
  305.     End If
  306.     Erase newMyPanels
  307. End If
  308. Looper = 0
  309. Looper = MDIchildren(CStr(hSubMenu))
  310. If Looper Then MDIchildren.Remove Looper
  311. ExitSub:
  312. End Sub
  313.  
  314. Private Sub Class_Terminate()
  315. ' =====================================================================
  316. ' Clean up variables, collections, etc for form closure
  317. ' =====================================================================
  318. On Error Resume Next
  319. Dim Looper As Long
  320. For Looper = 1 To PanelData.Count
  321.     pIDcurrent = Looper
  322.     If SideBarIsText = True Then DeleteObject MyPanels(PanelData.Item(Looper)).SBarIcon
  323. Next
  324. Set PanelData = Nothing
  325. Set MDIchildren = Nothing
  326. Set ImageLister = Nothing
  327. MainMenuID = 0
  328. OldWinProc = 0
  329. Set menuIDs = Nothing
  330. Erase MyMI
  331. End Sub
  332.  
  333. Private Sub Class_Initialize()
  334. Set menuIDs = New Collection
  335. Set PanelData = New Collection
  336. End Sub
  337.  
  338.  
  339.